package com.qf.student.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.student.entity.Studentinfo;
import com.qf.student.mapper.StudentinfoMapper;
import com.qf.student.service.StudentinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author Administrator
 * @version V1.0
 * @Project spring_student
 * @Package com.qf.student.service.impl
 * @Description: ${TODO}
 * @Date 2021/10/3 21:55
 */

@Service
public class StudentinfoServiceImpl implements StudentinfoService {

    @Autowired
    private StudentinfoMapper studentinfoMapper;

    @Override
    @Transactional
    public void insert(Studentinfo student) {
        int i = studentinfoMapper.insertSelective(student);
        if (i != 1){
            throw new RuntimeException("添加失败");
        }
    }

    @Override
    public PageInfo<Studentinfo> findAllByPage(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Studentinfo> list = studentinfoMapper.findAll();
        PageInfo<Studentinfo> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
}
